<?php

/*
 *  这是获取直播列表的接口
 */
global $_GPC, $_W;
$uniacid = $this->_uniacid;
$uid = $_W['member']['uid'];
$openid = $_W['openid'];
$operation = 'display';
 
if(isset($_GPC['op']) && !empty($_GPC['op'])){
    $operation = $_GPC['op'];
}
if($operation =='display'){
    load()->func('communication');     
        /*获取公众号access_token*/
    load()->classs('wxapp.account');
    $sql = 'select * from '.  tablename('account_wxapp'). " where uniacid= '".$uniacid."'";
    $account = pdo_fetch( $sql );       
    $accObj= new WxappAccount( $account);        
    $ACCESS_TOKEN = $accObj->getAccessToken( );  
    
    $qurl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=".$ACCESS_TOKEN;
    
    $ret =   ihttp_post($qurl, json_encode(array('start'=>0, 'limit'=>20)));
    if($ret['code']==200){
        $data = json_decode($ret['content'], true);
    
        if($data['errcode']==1){
            $this->result(1, '未创建直播间', $data);
        }
        if(!empty($data['room_info'])){
            $r = array();
            foreach($data['room_info'] as $key=>$val){
                $val['start_time'] = date('Y-m-d H:i:s', $val['start_time']);
                $val['end_time'] = date('Y-m-d H:i:s', $val['end_time']);
                $r[] = $val;
            }
           $this->result(0, 'success', $r);
        }
        
       
    }
  
}
  $this->result(1, '暂无直播间数据' , []); 
      
?>
